# -*- coding:utf-8 -*-
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
import re
import  shutil


def makedir(new_dir):
    if not os.path.exists(new_dir):
        os.makedirs(new_dir, mode=0o777)

if __name__ == '__main__':
    train_dir = os.path.join(BASE_DIR, '..', '..', "..", 'data', 'cats_dogs', 'train')
    # test_dir = os.path.join(BASE_DIR, '..', '..', '..', 'data', 'cats_dogs', 'test1')

    cats_dir = os.path.join(train_dir, 'cats')
    dogs_dir = os.path.join(train_dir, 'dogs')

    train_list = os.listdir(train_dir)
    makedir(cats_dir)  # 先列出训练集里面的所有图片名,再创建目录
    makedir(dogs_dir)
    for img_name in train_list:
        src_path = os.path.join(train_dir, img_name)
        if re.match('cat', img_name) is not None:
            # print(img_name)
            # print("*"*10)
            shutil.copy(src_path, cats_dir)
        elif img_name[:3] == 'dog':
            # print(img_name)
            # print('-----------------------')
            shutil.copy(src_path, dogs_dir)
